package cn.amoqi.springbootrocketmq.v2;

import cn.amoqi.springbootrocketmq.v2.config.MqProperties;
import cn.amoqi.springbootrocketmq.v2.service.MqClient;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description: m
 * @author: zhuiFeng
 * @date: 2021年04月17日 10:00
 */
@Component
public class MqHandle {

    public Map<String, MqClient> mqClientMap;

    private final MqProperties mqProperties;

    public MqHandle(MqProperties mqProperties, List<MqClient> mqClients) {
        this.mqProperties = mqProperties;
        this.mqClientMap = mqClients.stream().collect(Collectors.toMap(MqClient::support, Function.identity()));
    }

    public MqClient client() {
        return mqClientMap.get(mqProperties.getType());
    }

}
